﻿namespace RL
{
    using System;
    using System.Collections.Generic;

    public class BlockUI : PluginBase, IPlugin
    {
        private RL.AjaxPlaceHolder manager;

        internal BlockUI(RL.AjaxPlaceHolder Manager)
        {
            base.ScriptFiles.Add(Resources.Scripts.JQuery_BlockUI);
            this.manager = Manager;
        }

        public static string BlockElement(string selector, bool terminate)
        {
            Register();
            return ("$(" + selector + ").block()" + utility.terminater(terminate));
        }

        public static string BlockElement(string elementSelector, Mode mode, string text, bool terminate)
        {
            Register();
            switch (mode)
            {
                case Mode.htmlMessage:
                    return ("$(" + elementSelector + ").block({ message: '" + text + "' })" + utility.terminater(terminate));

                case Mode.DomElementSelector:
                    return ("$(" + elementSelector + ").block({ message: $(" + text + ") })" + utility.terminater(terminate));

                case Mode.NoMessage:
                    return ("$(" + elementSelector + ").block({ message: null })" + utility.terminater(terminate));

                case Mode.Css:
                    return ("$(" + elementSelector + ").block({ css: {" + text + "} })" + utility.terminater(terminate));

                case Mode.overlayCSS:
                    return ("$(" + elementSelector + ").block({ overlayCSS: {" + text + "} })" + utility.terminater(terminate));

                case Mode.Custom:
                    return ("$(" + elementSelector + ").block(" + text + ")" + utility.terminater(terminate));

                case Mode.NonCentered:
                    return ("$(" + elementSelector + ").block({ centerY: " + text + " })" + utility.terminater(terminate));
            }
            return string.Empty;
        }

        public static string BlockPage(bool terminate)
        {
            Register();
            return ("$.blockUI()" + utility.terminater(terminate));
        }

        public static string BlockPage(string text, Mode mode, bool terminate)
        {
            Register();
            switch (mode)
            {
                case Mode.htmlMessage:
                    return ("$.blockUI({ message: '" + text + "' })" + utility.terminater(terminate));

                case Mode.DomElementSelector:
                    return ("$.blockUI({ message: $(" + text + ") })" + utility.terminater(terminate));

                case Mode.NoMessage:
                    return ("$.blockUI({ message: null })" + utility.terminater(terminate));

                case Mode.Css:
                    return ("$.blockUI({ css: {" + text + "} })" + utility.terminater(terminate));

                case Mode.overlayCSS:
                    return ("$.blockUI({ overlayCSS: {" + text + "} })" + utility.terminater(terminate));

                case Mode.Custom:
                    return ("$.blockUI(" + text + ")");

                case Mode.NonCentered:
                    return ("$.blockUI({ centerY: " + text + " })" + utility.terminater(terminate));
            }
            return string.Empty;
        }

        private static void Register()
        {
            List<string> files = new List<string>();
            files.Add(Resources.Scripts.JQuery_BlockUI);
            utility.RegisterResources(files);
        }

        public static string UnblockElement(string elementSelector, bool terminate)
        {
            Register();
            return ("$(" + elementSelector + ").unblock()" + utility.terminater(terminate));
        }

        public static string UnblockPage(bool terminate)
        {
            Register();
            return ("$.unblockUI()" + utility.terminater(terminate));
        }

        public enum Mode
        {
            htmlMessage,
            DomElementSelector,
            NoMessage,
            Css,
            overlayCSS,
            Custom,
            NonCentered
        }
    }
}

